<!DOCTYPE html>
<html>

<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }

        body {
            background: #000 url(./assets/兴达八厂/背景兴达.jpg) no-repeat left top;
            background-size: 100%;
        }
    </style>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src='../custom/libs/echarts.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src="../conf/confURL.js"></script>
    <script src='../conf/dateTime.js'></script>
    <script src='../libs/plugin/ht-cssanimation.js'></script>
    <script src="../libs/plugin/ht-autolayout.js"></script>
    <script src='../libs/plugin/ht-dialog.js'></script>
    <script>
        var H = [];
        let warn = [];
        let table;
        let alarm;
        let diedai;
        let jichuang;
        let table1;
        let chart;
        let frame = document.createElement('iframe');
        var dialog = window.dialog = new ht.widget.Dialog();
        dataModel = new ht.DataModel();
        graphView = new ht.graph.GraphView(dataModel);
        let deptCode = "XD1112";
        //获取url
        var url = domain + "/HT_DATA_EIGHT.getGlobalStatistics.do"
        function init() {
            //获取图纸
            graphView.addToDOM();
            ht.Default.xhrLoad('displays/智慧兴达/兴达八厂/生产监控/product_eightFactory.json', function (text) {
                var json = ht.Default.parse(text);
                if (json.title) document.title = json.title;
                dataModel.deserialize(json);
                graphView.fitContent(true);
                tag();
                getData1(deptCode);
                getData2(deptCode);
                getData3(deptCode);
                getData4(deptCode);
                getData5(deptCode);
                getData6(deptCode);
                openInterval();
                setConfig(frame, dialog);
            });
            //时间刷新
            setInterval(function () {
                let dateTime = dataModel.getDataByTag('time');
                let time = updateTime();
                dateTime.a('time', time);
            }, 1000);
            //更新数据
            // 机床状态信息 与 车间报警灯 请求频率一致 20s;
            setInterval("getData3(deptCode)", 1000 * 20);
            // setInterval(getData1(), 1000 * 10);
            // setInterval(getData2(), 1000 * 60 * 5);
            // setInterval(getData4(), 1000 * 60 * 30);
        }
        //获取标签
        function tag() {
            for (let i = 1; i < 5; i++) {
                H.push(dataModel.getDataByTag("H" + i))
            }
            for (let i = 1; i < 5; i++) {
                warn.push(dataModel.getDataByTag("warn" + i))
            }
            table = dataModel.getDataByTag("table");
            alarm = dataModel.getDataByTag('alarm');
            diedai = dataModel.getDataByTag('diedai');
            jichuang = dataModel.getDataByTag("jichuang"); 
            table1 = dataModel.getDataByTag('table1');
            chart = dataModel.getDataByTag('chart') //车间 
        }
        //电镀报警信息接口
        function getData1(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_DDBJXXTJ",
                    deptCode: code

                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',    //application/json
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        warn[0].s("2d.visible", false)
                        alarm.s("2d.visible", true)
                        H[0].s("text", repData.HT_SC_FC_REPORT_DDBJXXTJ.title)
                        alarm.a("colData", repData.HT_SC_FC_REPORT_DDBJXXTJ.data)
                    } else {
                        warn[0].s("2d.visible", true)
                        alarm.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    //console.log('err');
                    warn[0].s("2d.visible", true)
                    alarm.s("2d.visible", false)
                }
            });
        }
        //工序维修费用统计接口
        function getData2(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_GXWXFYTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        warn[1].s("2d.visible", false)
                        diedai.s("2d.visible", true)
                        H[1].a("title", repData.HT_SC_FC_REPORT_GXWXFYTJ.title)
                        diedai.a("dataSource", repData.HT_SC_FC_REPORT_GXWXFYTJ.data)
                    } else {
                        warn[1].s("2d.visible", true)
                        diedai.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    // console.log('err');
                    warn[1].s("2d.visible", true)
                    diedai.s("2d.visible", false)
                }
            });
        }
        //机床状态统计接口
        function getData3(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_JCZTTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        warn[2].s("2d.visible", false)
                        jichuang.s("2d.visible", true)
                        table1.s("2d.visible", true)
                        H[3].a("title", repData.HT_SC_FC_REPORT_JCZTTJ.title)
                        table.a("ht.dataSource", repData.HT_SC_FC_REPORT_JCZTTJ.data)
                        table1.a("ht.dataSource", repData.HT_SC_FC_REPORT_JCZTTJ.total)
                    } else {
                        warn[2].s("2d.visible", true)
                        jichuang.s("2d.visible", false)
                        table1.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    //console.log('err');
                    warn[2].s("2d.visible", true)
                    jichuang.s("2d.visible", false)
                    table1.s("2d.visible", false)
                }
            });
        }
        //车间用电统计接口
        function getData4(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_CJYDTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        warn[3].s("2d.visible", false)
                        chart.s("2d.visible", true)
                        H[2].a("title", repData.HT_SC_FC_REPORT_CJYDTJ.title);
                        if(Boolean(repData.HT_SC_FC_REPORT_CJYDTJ.data)) {
                            chart.a("xAxis", repData.HT_SC_FC_REPORT_CJYDTJ.data.month);
                            chart.a("yAxis1", repData.HT_SC_FC_REPORT_CJYDTJ.data.workshop1);
                            chart.a("yAxis2", repData.HT_SC_FC_REPORT_CJYDTJ.data.workshop2);
                            chart.a("yAxis3", repData.HT_SC_FC_REPORT_CJYDTJ.data.workshop3);
                        }

                    } else {
                        warn[3].s("2d.visible", true)
                        chart.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    //console.log('err');
                    warn[3].s("2d.visible", true)
                    chart.s("2d.visible", false)
                }
            });
        }
        //返回按钮
        function getData5(code) {
            let backButton = dataModel.getDataByTag("backButton")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_BUTTON_RETURN",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_FC_BUTTON_RETURN.visible == "true") {
                        backButton.a("url", repData.HT_SC_FC_BUTTON_RETURN.data.url)
                        backButton.s("2d.visible", repData.HT_SC_FC_BUTTON_RETURN.visible)
                    }
                },
                error: function (error) {
                    // console.log('err');
                }
            });
        }
        //中间3车间
        function getData6(code) {
            let work11 = dataModel.getDataByTag("work1-1");
            let work12 = dataModel.getDataByTag("work1-2");
            let work13 = dataModel.getDataByTag("work1-3");
            let work14 = dataModel.getDataByTag("work1-4");
            let work21 = dataModel.getDataByTag("work2-1");
            let work22 = dataModel.getDataByTag("work2-2");
            let work3 = dataModel.getDataByTag("work3");
            let text1 = dataModel.getDataByTag("text1");
            let text2 = dataModel.getDataByTag("text2");
            let text3 = dataModel.getDataByTag("text3");
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_ZZ_FC_MAP",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_ZZ_FC_MAP.visible == "true") {
                        work11.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        work12.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        work13.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        work14.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        work21.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        work22.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        work3.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        text1.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        text2.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                        text3.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap);
                    }
                },
                error: function (error) {
                    // console.log('err');
                }
            });
        }
        //表格自动滚动
        function tableRun(){
            let  tabledata = table.a("ht.dataSource");
            if (tabledata != undefined && tabledata.length > 6) {
                let old = table.a('ht.translateY');
                table.a('ht.translateY', old - 45);
                tabledata.push(tabledata[0]);
                tabledata.splice(0, 1);
                table.a("ht.dataSource", tabledata);
                table.a('ht.translateY', old);
            }
        }
        //重新打开定时器，播放滚动
        function openInterval() {
            tableTimer = setInterval(tableRun, 2000);
        }
        // 报表弹出框
        function showDialog(url) {
            setFrameStyle(frame, dialog, url);
        }
    </script>
</head>

<body onload='setTimeout(init, 300)'>
</body>

</html>